import {homeMethod} from '@/utils/models/index.js'
const crudMethod = new homeMethod();
import {caseMethod} from '@/utils/models/case.js'
const caseMethods = new caseMethod();
import Footer from '@/components/footer-main'
export default {
  name: 'Home',
  components: { Footer},
  data() {
    return {
      query: {
        serveId: null,
        type: ''
      },
      loading: false,
      preview: [],
      loadCase: false,
      caseData: [],
      detail: '',
      articleBg: {
        backgroundImage: require('@/assets/images/companyNewsBg.png'),
        backgroundRepeat: 'no-repeat',
        backgroundPosition: 'center',
        backgroundSize: '100% 100%'
      },
    }
  },
  created() {
    this.query.serveId = this.$route.query.id
    this.getServeDetails()
    this.getServes()
  },
  methods: {
    goDetails(link) {
      this.query.serveId = link.serveId
      this.getServeDetails()
      this.getServes()
    },
    // 软件服务
    getServes () {
      let _this = this
      crudMethod.getServe().then((res) => {
        let {msg, code, data} = res;
        data.data.forEach(item => {
          if(_this.query.serveId == item.serveId) {
            _this.detail = item
            document.title = _this.detail.serveName
            _this.query.type = _this.detail.serveType
            _this.serveImg = _this.baseURL + _this.detail.serveImg
            _this.getCase()
          }
        })
      })
    },
    getServeDetails() {
      let _this = this
      _this.loading = true
      crudMethod.getServeDetail(_this.query.serveId).then((res) => {
        _this.loading = false
        let {msg, code, data} = res;
        _this.preview = data.data
      })
    },
    getCase() {
      let _this = this
      _this.loadCase = true
      caseMethods.getCase(_this.query.type).then((res) => {
        _this.loadCase = false
        let {msg, code, data} = res;
        data.data.forEach(item => {
          item.caseMinImg = item.caseMinImg ? item.caseMinImg.split(',') : []
          item.caseHoverImg = item.caseHoverImg ? item.caseHoverImg.split(',') : []
        })
        _this.caseData = data.data
      })
    }
  }
}
